package com.gmall.product.controller;

import com.gmall.common.result.Result;
import com.gmall.model.product.BaseCategory;
import com.gmall.model.product.dto.BaseCategoryDTO;
import com.gmall.model.product.dto.Category123IdNameDTO;
import com.gmall.product.service.BaseCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseCategory/")
public class BaseCategoryController {

    @Autowired
    BaseCategoryService baseCategoryService;
    @GetMapping("findCategoryTree")
    public Result<List<BaseCategoryDTO>> findCategoryTree(){
        return baseCategoryService.findCategoryTree();
    }


    @GetMapping("findCategoryTreeStream")
    public Result<List<BaseCategoryDTO>> findCategoryTreeStream(){
        return baseCategoryService.findCategoryTreeStream();
    }


    @GetMapping("getCategory1")
    public Result<List<BaseCategory>> getCategory1(){
        return baseCategoryService.getCategory1();
    }


    @GetMapping("getCategory2/{category1Id}")
    public Result<List<BaseCategory>> getCategory2(@PathVariable Long category1Id){
        return baseCategoryService.getCategory2(category1Id);
    }

    @GetMapping("getCategory3/{category2Id}")
    public Result<List<BaseCategory>> getCategory3(@PathVariable Long category2Id){
        return baseCategoryService.getCategory3(category2Id);
    }

    // 根据三级分类ID 找到一级分类ID，二级分类ID，一级分类名称，二级分类名称，三级分类名称
    @GetMapping("getCategory123IdNameDTO/{category3Id}")
    public Result<Category123IdNameDTO> getCategory123IdNameDTO(@PathVariable Long category3Id) {
        return baseCategoryService.findCategory123IdNameDTOByCategory3Id(category3Id);
    }
}
